<template>
  <section class="app-main">
    <router-view v-slot="{ Component }">
      <transition name="fade-transform" mode="out-in">
        <div class="route-view-wrapper">
          <keep-alive :include="cachedViews">
            <component :is="Component" :key="key" />
          </keep-alive>
        </div>
      </transition>
    </router-view>
  </section>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { useAppStore } from '@/stores/app'

const route = useRoute()
const appStore = useAppStore()

// 计算属性
// keep-alive 需要组件名，store 中应存放路由 name
const cachedViews = computed(() => appStore.cachedViews)
// 同一路由不同查询应重新渲染，使用 fullPath
const key = computed(() => route.fullPath)
</script>

<style lang="scss" scoped></style>

<style lang="scss"></style>
